package com.zzjson.mongo.demo.dao;

import com.zzjson.common.mongo.BaseDaoSupport;
import com.zzjson.common.mongo.QueryRule;
import com.zzjson.mongo.demo.entity.Hotel;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2019 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : com.zzjson.mongo.demo.dao</li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2019年04月02日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
@Repository
public class HotelDao extends BaseDaoSupport<Hotel, Long> {

    public List<Hotel> getById(String id) {

        QueryRule queryRule = QueryRule.getInstance();
        queryRule.andEqual(this.getPKColumn(), id);
        return super.find(queryRule);

    }

    @Override
    public List<Hotel> getAll() {

        QueryRule queryRule = QueryRule.getInstance();
        queryRule.addAscOrder("price");
        return super.find(queryRule);

    }

    @Override
    @Resource(name = "mongoTemplate")
    protected void setTemplate(MongoTemplate template) {
        super.setTemplate(template);
    }


    @Override
    protected String getPKColumn() {
        return "_id";
    }

}